package com.gnerv.sylvanas.framework.core.service;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * 通用事件发布服务
 */
@Service
public class EventPublishService {

    private final ApplicationEventPublisher applicationEventPublisher;

    public EventPublishService(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    @Async(value = "eventExecutor")
    public void asyncPublishEvent(ApplicationEvent event){
        applicationEventPublisher.publishEvent(event);
    }

    public void syncPublishEvent(ApplicationEvent event){
        applicationEventPublisher.publishEvent(event);
    }

}
